using System;
using System.Collections.Generic;
using System.Globalization;

namespace DotNETX.Utility
{
    public static class EnumUtils
    {
        /// <summary>
        /// Parses the specified enum member name, returning it's value.
        /// </summary>
        /// <param name="enumMemberName">Name of the enum member.</param>
        /// <returns></returns>
        public static T Parse<T>(string enumMemberName) where T : struct
        {
            return Parse<T>(enumMemberName, false);
        }

        /// <summary>
        /// Parses the specified enum member name, returning it's value.
        /// </summary>
        /// <param name="enumMemberName">Name of the enum member.</param>
        /// <param name="ignoreCase">If set to <c>true</c> ignore case.</param>
        /// <returns></returns>
        public static T Parse<T>(string enumMemberName, bool ignoreCase) where T : struct
        {
            if (!typeof(T).IsEnum) throw new ArgumentException((string.Format("Type {0} is not an Enum.", typeof(T))));

            return (T)Enum.Parse(typeof(T), enumMemberName, ignoreCase);
        }
    }
}